import sympy as sym
import numpy as np
from sympy import sin,cos,Function
import numbers
sym.init_printing()
#document:https://github.com/sympy/sympy


def iterable(arg):
    T = True
    try:
        for i in arg:
            pass
    except TypeError as err:
        T = False
    return T

def myPlus(arg_a, arg_b, flag = True):
    # res = []
    # if iterable(arg_a):
    #     if iterable(arg_b):
    #         for (item_a, item_b) in zip(arg_a, arg_b):
    #             if isinstance(item_a, numbers.Number):
    #                 item_a = sym.Rational(item_a)
    #             if isinstance(item_b, numbers.Number):
    #                 item_b = sym.Rational(item_b)
    #             res.append(item_a + item_b) 
    #         return res
    #         # return [sym.Add(item_a, item_b) for (item_a, item_b) in zip(arg_a, arg_b)]
    #     else:
    #         return [sym.Add(item_a, arg_b) for item_a in arg_a]
    # if iterable(arg_b):
    #     return [sym.Add(arg_a, item_b) for item_b in arg_b]

    # if not iterable(arg_a) and not iterable(arg_b):
    #     return sym.Add(arg_a, arg_b)
    if flag:
        return sym.simplify(np.array(arg_a) + np.array(arg_b))
    else:
        return np.array(arg_a) + np.array(arg_b)
    
x = sym.symbols('x')
y = sym.symbols('y')
A = [x,sin(x),2/3]
B = [x, x, 1]
f, g = sym.symbols('f,g', cls=Function)
f = x**2+ 3*x + 2
g = 3*x - 1

# res = myPlus(x, y)
# res1 = myPlus(x, A)
# res2 = myPlus(B, x)
# res3 = myPlus(f, g)
res4 = myPlus(A, B)

print(res4)
